<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="col-sm-12">
			<div class="ibox">
				<div class="ibox-body">
					<div class="panel panel-info">
				<div class="panel-heading">商品库商品销售统计列表</div>
			    <div class="panel-body">
			        <div class="form-horizontal">
		             <div class="form-group" style="padding-left:60px;">
		              <div class="col-xs-12 col-sm-3 hidden-xs btn-sespan" >
						<div class="input-group">
							<span class="input-group-addon" style="height:30px;">
								统计日期
							</span>
							<input type="text" name="startTime" id="startTime"
								   value="" placeholder="点击选择开始时间"
								   readonly class="datetimepicker form-control"
								   style="height:30px;"/>
							<span>
								<i class="fa fa-exchange"></i>
							</span>
							<input type="text"  name="endTime" id="endTime"
								   value="" placeholder="点击选择结束时间"
								   readonly class="datetimepicker form-control"
								   style="height:30px;"/>

						</div>
					 </div>
					   <div class="col-xs-12 col-sm-2 hidden-xs btn-sespan" >
					   <input name="title" id="title"  type="text" class="form-control"   placeholder="商品名称">
					   </div>
		              
		             <input type="hidden" name="centreId" th:value="${centreId}" th:if="${flag} == '1'">
		             <div class="columns pull-left col-md-1 nopadding">
							<select id="supplierId" name="supplierId"
								class="form-control chosen-select" tabindex="2">
								<option value="" selected>供应商</option>
								<option th:each="item: ${supply}" th:text="${item.name}"
										th:value="${item.id}"></option>
							</select>
						</div>
					 <div class="col-xs-12 col-sm-2 hidden-xs btn-sespan" th:if="${flag} == '0'">
						<select data-placeholder="商户" class="form-control chosen-select" id="centreId" name="centreId" tabindex="2">
							<option value="">选择商户</option>
							<option th:each="item: ${centreList}" th:text="${item.name}" th:value="${item.centreId}"></option>
						</select>
					 </div>
		            </div>
		            <div class="form-group">
		                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
		                <div class="col-sm-8 col-lg-9 col-xs-12">
		                    <button class="btn btn-default" onclick="reLoad()">
		                    	<i class="fa fa-search"></i> 搜索
		                    </button>
		                    <button type="button" class="btn btn-default" style='margin-left:10px;' onclick="exportExcel()">
								<span class="fa fa-download"></span>
								导出Excel
							</button>
		                </div>
		            </div>
			        </div>
			    </div>
			</div>
				<table id="prodAfterSaleTable" data-mobile-responsive="true">
					</table>
				</div>
			</div>
		</div>
	</div>
	<div th:include="centre/manage/include::footer"></div>
	<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
	<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
	<script type="text/javascript">
		function closeDow() {
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		}
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#startTime' , type: 'datetime'
            });

            laydate.render({
                elem: '#endTime' , type: 'datetime'
            });
        })


		var prefix = "/prod/aftersalestatic";
		$(document).ready(function () {
            var date = new Date();
            var year = date.getFullYear();
            var mon=date.getMonth()+1 < 10 ? "0"+(date.getMonth()+1+""):date.getMonth()+1;
            var da=date.getDate() < 10 ? "0"+ date.getDate():date.getDate();
            date.setDate(date.getDate()-1);
            var endyear = date.getFullYear();
            var endmon=date.getMonth()+1 < 10 ? "0"+(date.getMonth()+1+""):date.getMonth()+1;
            var endda=date.getDate() < 10 ? "0"+ date.getDate():date.getDate();
            $("#endTime").val(year+"-"+mon+"-"+da+" 20:05:00");
            $("#startTime").val(endyear+"-"+endmon+"-"+endda+" 20:30:00");
		    load();
		});
		function load() {
			$('#prodAfterSaleTable').bootstrapTable({
				method : 'get', // 服务器数据的请求方式 get or post
				url : prefix + "/prodstaticData", // 服务器数据的加载地址
				showRefresh : true,
				// showToggle : true,
				iconSize : 'outline',
				// toolbar: '#exampleToolbar',
				striped : true, // 设置为true会有隔行变色效果
				dataType : "json", // 服务器返回的数据类型
				pagination : true, // 设置为true会在底部显示分页条
				pageList : [ 10, 20, 50 ],
				// queryParamsType : "limit",
				// //设置为limit则会发送符合RESTFull格式的参数
				singleSelect : false, // 设置为true将禁止多选
				// contentType : "application/x-www-form-urlencoded",
				// //发送到服务器的数据编码类型
				pageSize : 10, // 如果设置了分页，每页数据条数
				pageNumber : 1, // 如果设置了分布，首页页码
				// search : true, // 是否显示搜索框
				showColumns : true, // 是否显示内容下拉框（选择显示的列）
				showFooter : true,
				sidePagination : "server", // 设置在哪里进行分页，可选值为"client" 或者
				// "server"
				queryParams : function(params) {
                    /* if($.trim($("#supplyName").val())==0){
                        var title = $.trim($("#title").val());
                    }else{
                        var supplyName = $.trim($("#title").val());
                    } */
					return {
                    	limit : params.limit,
						offset : params.offset ,
						startTime: $.trim($("#startTime").val()),
						endTime: $.trim($("#endTime").val()),
						supplierId: $.trim($("#supplierId").val()),
						centreId:$.trim($("#centreId").val()),
						title:$.trim($("#title").val())
					};
				},
				columns: [
				{
				    title: '商品ID',
				    field: 'id',
				},
                {
                    title: '商品名称',
                    field: 'title',
                },
                {
                    title: '商品规格',
                    field: 'specTitle',
                },
                {
                    title: '成本价',
                    field: 'costprice',
                },
                {
                    title: '单价',
                    field: 'marketprice',
                },
                {
                    title: '销售数量',
                    field: 'salVolus',
                },
                {
                    title: '销售金额',
                    field: 'salesAmount',
                },
                {
                    title: '售后数量',
                    field: 'afterSaleCount',
                },
                {
                    title: '售后总金额',
                    field: 'afterSaleAmt',
                },
                {
                    title: '平台销售总额',
                    field: 'salesAllAmt',
                },
                {
                    title: '平台售后总额',
                    field: 'salesAfterAllAmt',
                },
                {
                    title: '平台售后率',
                    field: 'salesAfterRate',
                },
                {
                    title: '商品售后率',
                    field: 'prodSaleAfterRate',
                },
                {
                    title: '差异',
                    field: 'diffr',
                },
                {
                    title: '供应商',
                    field: 'supplier',
                },
                {
                    title: '买手',
                    field: 'buyrealnm',
                }
                ],
                onPostBody: function(){
                    countNum();
                }
			});
		}
		function reLoad() {
			$('#prodAfterSaleTable').bootstrapTable('refresh');
		}
		
	 

        function exportExcel() {
           var startTime= $.trim($("#startTime").val());
		   var	endTime= $.trim($("#endTime").val());
			var supplierId= $.trim($("#supplierId").val());
			var centreId=$.trim($("#centreId").val());
			var title=$.trim($("#title").val());
            window.location.href = prefix + "/export?startTime=" + startTime +
                "&endTime=" + endTime +"&supplierId=" + supplierId +"&centreId=" + centreId +
                "&title=" + title ;
        }
 

        function countNum() {
         
        }
	</script>
</body>
</html>